java
php
iphone
ajax
linux
xcode
visual-studio
silverlight
flash
html5
json
perl
facebook
oracle
apache
mvc
php5
asp
postgresql
dom
Each file included must be able to be parsed on its own without a syntax error. Your header has a syntax error of an unclosed if block. Likewise, the footer has a syntax error of an else block coming out of nowhere. You cannot do it this way.
Instead you can use something like:
// Global variable defined above includes: $condition = TRUE; include('header.php'); echo "The great brown fox jumps over the lazy dog."; include('footer.php'); // header.php if ($condition) { echo "hello world"; } // footer.php if (!$condition) { echo "bye"; }
Also using output buffing to grab content is way better then just including raw html into your code flow.
<?php function get_page_section($path){ if(file_exists($path)){ //grab "output" to the return variable ob_start(); require($path); $return = ob_get_contents(); ob_end_clean(); return $return; }else{ //path not found throw new Exception('get_page_section('.$path.') not found'); } } $header = get_page_section('header.php'); $footer = get_page_section('footer.php'); echo $header. "The great brown fox jumps over the lazy dog.". $footer; ?>
in header.php type the following code
<?php if(true){ echo "Helloworld"; }else{ echo "bye bye"; exit(); } ?>
in the body.php continue as you wrote before
<?php include('header.php'); echo "The great brown fox jumps over the lazy dog.";
this is the simplest way you can solve the probelm and hope this would help